package com.minelx.statementplus.ui.form.dao;

import com.minelx.sqlstructures.statements.clause.AndBuilder;
import com.minelx.sqlstructures.statements.clause.Sql;

import java.util.List;

public class ConditionsListModel extends BaseListModel<Sql> {
	private final AndBuilder whereClauseBuilder;

	public ConditionsListModel(AndBuilder whereClauseBuilder) {
		this.whereClauseBuilder = whereClauseBuilder;
	}

	@Override
	public int getSize() {
		return whereClauseBuilder.conditions().size();
	}

	@Override
	public Sql getElementAt(int index) {
		return Sql.of(whereClauseBuilder.conditions().get(index));
	}

	public void append(Sql condition) {
		whereClauseBuilder.add(condition.toText());
	}

	public void remove(int index) {
		whereClauseBuilder.remove(index);
	}

	@Override
	public void removeAll() {
		whereClauseBuilder.removeAll();
	}

	@Override
	public List<Sql> toList() {
		throw new RuntimeException("ConditionsListModel.toList is not implemented yet.");
	}
}
